<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>质保邮件推送管理</title>

    <link rel="stylesheet" href="/css/vendor/common.css" type="text/css">
    <link rel="stylesheet" href="/css/vendor/cmp-controls.css" type="text/css">
    <link href="/css/vendor/dispatch-email.less" rel="stylesheet/less" type="text/css">
    <script src="/js/less.min.js"></script>

</head>

<body>

<main>
    <div class="group-select-1-wrap">
        <h1>质保推送管理:</h1>

        <div class="group-select">
            <div class="left-zone">
                <div class="title">
                    <label>选择您要添加的推送人</label>
                </div>
                <div class="list-wrap">
                    <ul id="group-select-src-list">
                    </ul>
                </div>
            </div>

            <div class="right-zone">
                <div class="title">
                    <label>已选择推送人</label>
                </div>
                <div id="group-select-dest-list-wrap" class="list-wrap">
                    <ul id="group-select-dest-list">
                    </ul>
                </div>
            </div>

            <dic class="seperate-line"></dic>
        </div>

        <div class="bottom-bar">
            <label class="count">已选择<span id="group-select-dest-count">0</span><span class="cnt-unit">个推送人</span></label>
            <div class='btn-h button confirm' onClick=groupSelcetM.clickConfirm()>更 新</div>
        </div>
    </div>
</main>
<div id="userList" style="display: none">{{ userList }}</div>
</body>

<script src="/js/jquery-3.2.1.min.js"></script>
<script src="/js/vendor/cmp-controls.js"></script>
<script src="/js/vendor/dispatch-email.js"></script>

<script>


    var targetCheckedList=new Array();

    function loadCheckedList(targetList){
        targetCheckedList=new Array();
        var srcList = new Array();
        for(var i=0;i<targetList.length;i++){
            var targetItem=targetList[i];
            var detailStr="";
            if(targetItem.nickname){
                detailStr="昵称:"+targetItem.nickname+"";
            }else{
                detailStr="昵称:未设置";
            }
            if(targetItem.email){
                detailStr+=" 邮箱:"+targetItem.email;
            }else{
                detailStr+=" 邮箱:未设置";
            }
            var isChecked=false;
            if(targetItem.remind_id&&targetItem.remind_id>0){
                isChecked=true;
            }

            var item = {// icon:"group_selcet_head_icon.png",
                icon:targetItem.icon_url,
                uid:targetItem.phone,
                detail: detailStr,
                id:targetItem.id,
                email:targetItem.email,
                nickname:targetItem.nickname,
                checked:isChecked
            };
            if(isChecked){
                targetCheckedList[item.uid]=item;
            }
            srcList.push(item);
        }


        groupSelcetM.updateSrcList(srcList);
    }

    $(function(){
        groupSelcetM.init();
        var targetList=eval("("+$("#userList").text()+")");
        loadCheckedList(targetList);

        groupSelcetM.filterSrcDataCallback = function(value) {
            FAlert("过滤源数据: "+value);
        };
        groupSelcetM.confirmCallback = function(list) {

            if(!list||list.length<=0){
                FAlert("请选择推送人");
                return ;
            }
            var targetAddList=new Array();
            var targetRemoveList=new Array();

            for(var j=0;j<list.length;j++){
                var uid=list[j].uid;
                if(!list[j].email){
                    var str="选择用户:"+list[j].uid+",其邮箱为空,无法添加为推送人";
                    FAlert(str);
                    return;
                }else{
                    var obj=targetCheckedList[uid];
                    if(!obj){
                        targetAddList.push(list[j]);
                    }else{
                        obj["no_delete"]=true;
                    }
                }
            }

            for(var item in targetCheckedList){
                var obj=targetCheckedList[item];
                if(!obj["no_delete"]){
                    targetRemoveList.push(obj);
                }
                obj["no_delete"]=false;
            }

            $.post("/notification/updateDispatchEmail",{
                "add":targetAddList,
                "remove":targetRemoveList
            },function(result){
                if(result.status==0){
                    FAlert("操作成功");

                    loadCheckedList(result.data);

                }else{
                    FAlert("操作失败");
                }


            });


        };

    });



</script>

</html>
